#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;
const int N = 16;
int n;
int state[N];
int used[N];
void dfs(int u)
{
    if (u > n)
    {
        for (int i = 1; i <= n; i++)
            printf("%d ", state[i]);
        printf("\n");
        return;
    }
    for (int i = 1; i <= n; i++)
    {
        if (!used[i])
        {
            state[u] = i;
            used[i] = 1;
            dfs(u + 1);
            used[i] = 0;
        }
    }
}

int main()
{
    cin >> n;
    dfs(1);
    return 0;
}